
import { ref } from 'vue';
import { updatePaperPurchaseOrderRevokeReconciliationApi } from '@/api/sj/purchaseManagement/paperProcurement/index';

const useReconciliation = () => {

    const reconciliationVisible = ref(false);
    const reconciliationRow = ref({});

    /**
     * @description: 打开对账
     */
    const handleOpenReconciliation = (row: any) => {
        console.log(row);
        reconciliationRow.value = row;
        reconciliationVisible.value = true;

        //         无法对账，可能的原因：1未审批2先付款的订单，还有入
        // 库记录未选中3.不是同一批产品
    };

    /**
     * @package 撤销对账
     */

    const handleRevoke = async (row: any, fn: Function) => {
        ElMessageBox.confirm('确定要撤销对账吗？', '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning'
        })
            .then(async () => {
                try {
                    const { code } = await updatePaperPurchaseOrderRevokeReconciliationApi({ id: row.id });
                    if (code == 200) {
                        ElMessage({
                            type: 'success',
                            message: '撤销成功!'
                        });
                        fn();
                    }
                } catch (error) { }
            })
            .catch(() => { });
    }


    return {
        reconciliationVisible,
        reconciliationRow,
        handleRevoke,
        handleOpenReconciliation,
    }
};

export default useReconciliation;